<?php
namespace app\home\controller;

use think\Controller;
use think\Db;
use think\Session;
use app\home\model\User;
//use \think\Request;

// class Login extends Controller
class Login extends Controller
{   
    public function index()
    {   
        return view();
    }




    public function login($user_number='',$password=''){

       /* $request = request();
        var_dump($request);*/
        // var_dump(input('post.'));
        
        
        $user = User::get([
            'user_number' => $user_number,
            'password' => md5($password)
        ]);
        // var_dump($user->username);
        // exit();

        if($user){
            $newtime=time();
            $birth=$user->birth;
            $age=date('Y',$newtime)-date('Y',$birth);
            Session::set('user.id',$user->id);
            Session::set('user.username',$user->username);
            Session::set('user.age',$age);
            Session::set('user.user_number',$user->user_number);
            Session::set('user.img_src',$user->img_src);
            Session::set('user.living_place',$user->living_place);
            Session::set('user.sex',$user->sex);
            Session::set('user.constellation',$user->constellation);
            return $this->success("登入成功!",'hecenter/index');
        }else{
            return $this->error('登录失败');
        }
    }
    public function out(){
        Session::delete('user');
        return $this->success("退出成功!",'login/index');
    }
}
